// house_pkg/pages/room/index.ts
Page({

  /**
   * 页面的初始数据
   */
  data: {
    point: '',
    building: '',
    rooms: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad({ point, building }) {
    this.fake(point, building)
  },

  fake(point, building) {
    // 先随机一个房子数量 4-8
    const size = Math.floor(Math.random() * 5) + 4
    // 创建房子储存变量
    const rooms = []
    // 循环创建房子
    for (let index = 0; index < size; index++) {
      // 生成楼层
      const floor = Math.floor(Math.random() * 20) + 1
      // 生成房间号
      const No = Math.floor(Math.random() * 3) + 1
      // 拼接成字符串
      const currentRoom = [floor, '0', No].join('')

      // 如果有重复就放弃, 继续下个循环
      if (rooms.includes(currentRoom)) continue
      // 如果没有重复, 就放入数组中
      rooms.push(currentRoom)
    }

    this.setData({
      point,
      building,
      rooms
    })

  },

  goForm(ev) {
    wx.navigateTo({
      url: `/house_pkg/pages/form/index?point=${this.data.point}&building=${this.data.building}&room=${ev.mark.room}`
    });

  }
})